package com.xktpx.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xktpx.common.utils.R;
import com.xktpx.entity.SaleOrderEntity;
import com.xktpx.entity.model.SaleGoods;
import com.xktpx.result.BaseResult;
import com.xktpx.service.BuyOrderService;
import com.xktpx.service.SaleOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 杨浩
 * @create 2018-12-30 14:58
 **/
@RestController
@RequestMapping("/api/mySell")
@Api(tags = "我的-出售")
public class ApiMySellController {

    @Autowired
    private SaleOrderService saleOrderService;

    @Autowired
    private BuyOrderService buyOrderService;

    @ApiOperation("出售-出售中")
    @GetMapping("/myShipment")
    public BaseResult<List<SaleOrderEntity>> myShipment(@ApiParam("当前页码") @RequestParam("pageNo") String pageNo,
                                                        @ApiParam("每页显示条数") @RequestParam("pageSize") String pageSize,
                                                        @ApiParam("用户id") @RequestParam("userId") Long userId) {

        return BaseResult.success(saleOrderService.queryMyShipment(pageNo, pageSize, userId, 0));
    }

    @ApiOperation("出售-未发货")
    @GetMapping("/myUnshipped")
    public BaseResult<List<SaleOrderEntity>> myUnshipped(@ApiParam("当前页码") @RequestParam("pageNo") String pageNo,
                                                         @ApiParam("每页显示条数") @RequestParam("pageSize") String pageSize,
                                                         @ApiParam("用户id") @RequestParam("userId") Long userId) {

        return BaseResult.success(saleOrderService.queryMyShipment(pageNo, pageSize, userId, 0));
    }

    @ApiOperation("出售-已发货")
    @GetMapping("/myShipped")
    public BaseResult<List<SaleOrderEntity>> myShipped(@ApiParam("当前页码") @RequestParam("pageNo") String pageNo,
                                                       @ApiParam("每页显示条数") @RequestParam("pageSize") String pageSize,
                                                       @ApiParam("用户id") @RequestParam("userId") Long userId) {

        return BaseResult.success(saleOrderService.queryMyShipment(pageNo, pageSize, userId, 0));
    }

    @ApiOperation("出售-历史订单")
    @GetMapping("/mySaleHistorical")
    public BaseResult<List<SaleOrderEntity>> mySaleHistorical(@ApiParam("当前页码") @RequestParam("pageNo") String pageNo,
                                                              @ApiParam("每页显示条数") @RequestParam("pageSize") String pageSize,
                                                              @ApiParam("用户id") @RequestParam("userId") Long userId) {

        return BaseResult.success(saleOrderService.queryMyShipment(pageNo, pageSize, userId, 0));
    }

    @ApiOperation("查询卖家订单详情")
    @GetMapping("/querySellerOrderInfo")
    public R querySellerOrderInfo(@ApiParam("订单ID") @RequestParam("orderId") Integer orderId) {
        //表单校验
        Map<String, Object> map = new HashMap<>(1);
        SaleOrderEntity order = saleOrderService.selectOne(new EntityWrapper<SaleOrderEntity>().eq("orderId", orderId));
        if (order != null) {
            map.put("orderDetail", order);
        }
        //用户登录
        return R.ok(map);
    }

    @ApiOperation("卖家支付保证金")
    @GetMapping("/sellerDownpayment")
    public R sellerDownpayment(@ApiParam("订单ID") @RequestParam("orderId") Integer orderId,
                               @ApiParam("金额") @RequestParam("price") BigDecimal price) {
        //表单校验


        //用户登录
        return R.ok();
    }

    @ApiOperation("卖家发货")
    @GetMapping("/sellerDelivery")
    public R sellerDelivery(@ApiParam("订单ID") @RequestParam("orderId") Integer orderId) {
        //表单校验


        //用户登录
        return R.ok();
    }


}
